package com.gmail.blackdog1987.carcare.model;

import java.util.Date;
import java.util.List;

import com.gmail.blackdog1987.carcare.App;
import com.gmail.blackdog1987.carcare.R;
import com.gmail.blackdog1987.carcare.db.BaseModel;

public class User  extends BaseModel implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5917629381268828705L;
	public int id;    // id
	public String mobile;  // 手机
	public String email;   // 电邮
	public String nickname;   // 昵称
	public int sex;    // 性别
	public long birthday;    // 生日
	public int constellation;   // 星座
	public String emotion;     // 情感状态
	public String looks;     // 外貌
	public String job;      // 职业
	public String interests;   // 兴趣
	public String language;    // 语言
	public String company;    // 公司
	public String sextend;     // 性取向
	public String birthplace;    // 出生地
	public String school;     // 学校
	public String specialinterests;    // 特殊癖好
	public String headicon;      // 头像url
	public String activetype;     // 活动类型
	public long lastlogin;      // 上次登陆
	public int lastlocationX;    // 上次登陆坐标
	public int lastlocationY;     //  上次登陆坐标
	public int level;         // 等级
	public int favorcount;     // 关注数
	public String account;       // 账号
	public String pwd;            // 密码

	/** 表名称 */
	public static final String TABLE = "t_user";

	public enum Field {
		id,
		mobile,
		email,
		nickname,
		sex,
		birthday,
		constellation,
		emotion,
		looks,
		job,
		interests,
		language,
		company,
		sextend,
		birthplace,
		school,
		specialinterests,
		headicon,
		activetype,
		lastlogin,
		lastlocationX,
		lastlocationY,
		level,
		favorcount,
		account,
		pwd;
	};
	
	/**
	 * 创建model.T_User
	 */
	public User() {}

	@Override
	public List<String> getCreateSqlList() {
		mCreateSqlList.clear();
		StringBuilder createSql = new StringBuilder();
		createSql.append("CREATE TABLE if not exists " + TABLE + " (");
		createSql.append(Field.id + "               integer    primary key    autoincrement,");
		createSql.append(Field.mobile + "   	    text	,");
		createSql.append(Field.email + "      text	,");
		createSql.append(Field.nickname + "      text	,");
		createSql.append(Field.sex + "      integer	,");
		createSql.append(Field.birthday + "        integer	,");
		createSql.append(Field.constellation + "         integer	,");
		createSql.append(Field.looks + "         text	,");
		createSql.append(Field.job + "         text	,");
		createSql.append(Field.interests + "         text	,");
		createSql.append(Field.language + "         text	,");
		createSql.append(Field.company + "         text	,");
		createSql.append(Field.sextend + "         text	,");
		createSql.append(Field.birthplace + "         text	,");
		createSql.append(Field.school + "         text	,");
		createSql.append(Field.specialinterests + "         text	,");
		createSql.append(Field.headicon + "         text	,");
		createSql.append(Field.activetype + "         text	,");
		createSql.append(Field.lastlogin + "         integer	,");
		createSql.append(Field.lastlocationX + "         integer	,");
		createSql.append(Field.lastlocationY + "         integer	,");
		createSql.append(Field.level + "         integer	,");
		createSql.append(Field.favorcount + "         integer	,");
		createSql.append(Field.account + "         text	,");
		createSql.append(Field.pwd + "         text	,");
		createSql.append(Field.emotion + "         text);");
		
		mCreateSqlList.add(createSql.toString());
		return super.getCreateSqlList();
	}

	@Override
	public List<String> getUpgradeSqlList(int oldVersion) {
		mUpgradeSqlList.clear();
		return super.getUpgradeSqlList(oldVersion);
	}
	
	
	/**
	 * 根据出生日期算年龄
	 */
	public static int getAge(Date date){
		if(date!=null){
			return (int) Math.ceil((((date.getTime()/1000l)/60l)/60l)/24l);
		}
		return 0;
	}
	
	/**
	 * 根据出生日期算年龄
	 */
	public static int getAge(long date){
		if(date!=0){
			return getAge(new Date(date));
		}
		return 0;
	}
	
	/**
	 * 根据出生日期算星座
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public static String getConstellation(Date date){
		if(date==null)
			return null;
		final int[] constellationEdgeDay = { 19,18,20,19,20,21,22,22,22,23,22,21};
		int constellationIndex = 0;
		if(date.getDate()>constellationEdgeDay[date.getMonth()]){
			constellationIndex = date.getMonth()+1;
		}else{
			constellationIndex = date.getMonth();
		}
		return App.getInstance().getResources().getStringArray(R.array.constellation)[constellationIndex];
	}
	
	/**
	 * 根据出生日期算星座
	 * @return
	 */
	public static String getConstellation(long date){
		if(date==0){
			return null;
		}
		return getConstellation(new Date(date));
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public long getBirthday() {
		return birthday;
	}

	public void setBirthday(long birthday) {
		this.birthday = birthday;
	}

	public int getConstellation() {
		return constellation;
	}

	public void setConstellation(int constellation) {
		this.constellation = constellation;
	}

	public String getEmotion() {
		return emotion;
	}

	public void setEmotion(String emotion) {
		this.emotion = emotion;
	}

	public String getLooks() {
		return looks;
	}

	public void setLooks(String looks) {
		this.looks = looks;
	}

	public String getJob() {
		return job;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public String getInterests() {
		return interests;
	}

	public void setInterests(String interests) {
		this.interests = interests;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getSextend() {
		return sextend;
	}

	public void setSextend(String sextend) {
		this.sextend = sextend;
	}

	public String getBirthplace() {
		return birthplace;
	}

	public void setBirthplace(String birthplace) {
		this.birthplace = birthplace;
	}

	public String getSchool() {
		return school;
	}

	public void setSchool(String school) {
		this.school = school;
	}

	public String getSpecialinterests() {
		return specialinterests;
	}

	public void setSpecialinterests(String specialinterests) {
		this.specialinterests = specialinterests;
	}

	public String getHeadicon() {
		return headicon;
	}

	public void setHeadicon(String headicon) {
		this.headicon = headicon;
	}

	public String getActivetype() {
		return activetype;
	}

	public void setActivetype(String activetype) {
		this.activetype = activetype;
	}

	public long getLastlogin() {
		return lastlogin;
	}

	public void setLastlogin(long lastlogin) {
		this.lastlogin = lastlogin;
	}

	public int getLastlocationX() {
		return lastlocationX;
	}

	public void setLastlocationX(int lastlocationX) {
		this.lastlocationX = lastlocationX;
	}

	public int getLastlocationY() {
		return lastlocationY;
	}

	public void setLastlocationY(int lastlocationY) {
		this.lastlocationY = lastlocationY;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getFavorcount() {
		return favorcount;
	}

	public void setFavorcount(int favorcount) {
		this.favorcount = favorcount;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
}
